#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e6 + 10, INF = 0x3f3f3f3f, mod = 998244353;

ll x, y;
ll a0, a1, b;
ll p0, p1;

ll ksm(ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod, b >>= 1;
    }
    return res;
}

ll inv(ll a) { return ksm(a, mod - 2); }

ll mul(ll a, ll b) { return (a % mod) * (b % mod) % mod; }

ll dfs(ll x, ll y, ll p)
{
    if (x == 0) return 0;//x必输
    if (y == 0) return p;
    if (x > y) {//x > y，表示x输k场后任然保证自己赢
        ll k = x / y;
        ll cur = ksm(p1, k);
        return (mul(((1 - cur) % mod + mod) % mod, p) + dfs(x % y, y, mul(cur, p))) % mod;
        //(1 - cur)表示y输的情况， cur为y赢k次的概率，对立面就是y没有赢k次的概率，在加上dfs(x % y, y)下的概率
    } else {
        //x <= y,表示x需要连赢k场才能保证x赢
        ll k = y / x;
        ll cur = ksm(p0, k);
        return dfs(x, y % x, mul(cur, p));
    }
}

void solve()
{
    cin >> x >> y >> a0 >> a1 >> b;
    b = a0 + a1;
    p0 = mul(a0, inv(b));
    p1 = mul(a1, inv(b));
    cout << dfs(x, y, 1) << '\n';
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    cin >> T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}